$(function() {
	var act = "add";
	var cid = null;
	$(".dform button[type=button]").click(function() {
		if ($("#name").val() == '') {
			alert("请输入名称");
			return;
		}
		var url = "admin/department/department!"+act;
		var ps = $(".dform").serialize();
		if (act == "update2") {
			ps += "&usedProps=name&usedProps=sortNum&bean.id=" + cid;
		}
		doPost(url, ps, function() {
			doGet("admin/department/department!room");
		});
	});
	$("div.room ul li a.remove").click(
			function() {
				var did = $(this).attr("did");
				var p = $(this).parent();
				doSubmit("admin/department/department!remove",
						"bean.id=" + did, function() {
							p.remove();
						});
			});

	$("div.room ul li a.dname").click(function() {
		$("#name").val($(this).text());
		$("input.sort").val($(this).attr("sort"));
		cid = $(this).attr("did");
		act = "update2";

	});

	$(".dform button[type=reset]").click(function() {
		$(".dform")[0].reset();
		act = "add";
	});

});